{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2563dafc",
   "metadata": {},
   "source": [
    "### PCA降维"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "ce1a532f",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "from sklearn import datasets\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "# decomposition 降解，降维，分解【由多变少】\n",
    "from sklearn.decomposition import PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5258800c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(150, 4)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
       "       0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
       "       1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
       "       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#加载数据\n",
    "X,y = datasets.load_iris(return_X_y=True)\n",
    "display(X.shape, y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "f8776e88",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.1, 3.5, 1.4, 0.2],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.6, 1.4, 0.2]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786,  0.64836932],\n",
       "       [-1.31993521, -0.35930856],\n",
       "       [-1.40496732, -0.29424412],\n",
       "       [-1.33510889, -0.64613986],\n",
       "       [-1.32702321,  0.6633044 ]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([-1.45365201e-15, -1.76747506e-15])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([0.99666109, 0.99666109])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pca = PCA(n_components=2, # 选择两个特征\n",
    "          whiten=True) # 归一化\n",
    "pca.fit(X) # 训练，计算过程\n",
    "X_pca = pca.transform(X) # 转变\n",
    "display(X[:5],X_pca[:5],X_pca.mean(axis = 0),X_pca.std(axis = 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "bc1c18fa",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[5.1, 3.5, 1.4, 0.2],\n",
       "       [4.9, 3. , 1.4, 0.2],\n",
       "       [4.7, 3.2, 1.3, 0.2],\n",
       "       [4.6, 3.1, 1.5, 0.2],\n",
       "       [5. , 3.6, 1.4, 0.2]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786,  0.64836932],\n",
       "       [-1.31993521, -0.35930856],\n",
       "       [-1.40496732, -0.29424412],\n",
       "       [-1.33510889, -0.64613986],\n",
       "       [-1.32702321,  0.6633044 ]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([-1.45365201e-15, -1.76747506e-15])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([0.99666109, 0.99666109])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "pca = PCA(n_components=0.97, # #选择特征权重大于95%\n",
    "          whiten=True) # 归一化\n",
    "pca.fit(X) # 训练，计算过程\n",
    "X_pca = pca.transform(X) # 转变\n",
    "display(X[:5],X_pca[:5],X_pca.mean(axis = 0),X_pca.std(axis = 0))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "7d5c4483",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9333333333333333"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练模型（非降维数据）\n",
    "from sklearn.model_selection import train_test_split\n",
    "X_train,X_test,y_train,y_test = train_test_split(X,y, test_size=0.1)\n",
    "model = LogisticRegression()\n",
    "model.fit(X_train, y_train)\n",
    "model.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4fd482cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9333333333333333"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练模型(降维数据)\n",
    "X_train,X_test,y_train,y_test = train_test_split(X_pca,y, test_size=0.1)\n",
    "model = LogisticRegression()\n",
    "model.fit(X_train, y_train)\n",
    "model.score(X_test, y_test)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1793fc85",
   "metadata": {},
   "source": [
    "### 协方差散度矩阵"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "256633ec",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b8489088",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[11,  7,  5],\n",
       "       [ 2, 13, 19],\n",
       "       [15,  7, 17]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[  9.33333333, -26.33333333,   0.        ],\n",
       "       [-26.33333333,  74.33333333,   1.        ],\n",
       "       [  0.        ,   1.        ,  28.        ]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "A = np.random.randint(1,20, size=(3,3))\n",
    "#协方差\n",
    "cov = np.cov(A, rowvar=True)\n",
    "display(A, cov)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "40ab4787",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  9.33333333, -26.33333333,   0.        ],\n",
       "       [-26.33333333,  74.33333333,   1.        ],\n",
       "       [  0.        ,   1.        ,  28.        ]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#散度矩阵\n",
    "B = (A - A.mean(axis=1).reshape(-1,1))\n",
    "scatter = B.dot(B.T)\n",
    "display(scatter/(3-1))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "26fdc97c",
   "metadata": {},
   "source": [
    "### 特征值和特征向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "e7195680",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "98b087b0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 9, 5],\n",
       "       [1, 2, 6],\n",
       "       [4, 6, 0]])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.random.randint(0,10, size=(3,3))\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "2f177d8c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([10.79826148+0.j        , -3.39913074+0.92483254j,\n",
       "       -3.39913074-0.92483254j])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0.73818072+0.j        ,  0.5707298 +0.22100107j,\n",
       "         0.5707298 -0.22100107j],\n",
       "       [ 0.43533602+0.j        , -0.62439407+0.j        ,\n",
       "        -0.62439407-0.j        ],\n",
       "       [ 0.51533657+0.j        ,  0.46674257-0.13307684j,\n",
       "         0.46674257+0.13307684j]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "w,v = np.linalg.eig(A)\n",
    "display(w,v)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de9d73b4",
   "metadata": {},
   "source": [
    "### 手写实现PCA降维"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "86da8dd7",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn import datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "9e595438",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786,  0.64836932],\n",
       "       [-1.31993521, -0.35930856],\n",
       "       [-1.40496732, -0.29424412],\n",
       "       [-1.33510889, -0.64613986],\n",
       "       [-1.32702321,  0.6633044 ]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X,y = datasets.load_iris(return_X_y=True)\n",
    "#去中心化\n",
    "B = X - X.mean(axis=0)\n",
    "#协方差\n",
    "\n",
    "V = np.cov(B, rowvar=False, bias=True) # 以列来进行计算的，列是特征\n",
    "\n",
    "#特征向量和特征值\n",
    "w,v = np.linalg.eig(V)\n",
    "# 符号翻转，绝对值最大的，如果是负数，才翻转\n",
    "max_abs_cols = np.argmax(np.abs(v),axis = 0)\n",
    "signs = np.sign(v[max_abs_cols,[0,1,2,3]]) # 检索\n",
    "v *= signs # 根据条件进行翻转\n",
    "\n",
    "#特征的筛选\n",
    "cond = (w/w.sum()).cumsum() >= 0.95\n",
    "index = cond.argmax()\n",
    "v_ = v[:,:index + 1] # 特征向量筛选\n",
    "\n",
    "# 举证运算\n",
    "pca_result = B.dot(v_)\n",
    "pca_result = (pca_result - pca_result.mean(axis =0))/pca_result.std(axis=0,ddof = 1)\n",
    "pca_result[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "db86d057",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.85667061, 0.73016143, 0.59791083, 0.75365743])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_abs_cols = np.argmax(np.abs(v),axis = 0)\n",
    "v[max_abs_cols,[0,1,2,3]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "14e1d047",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 1., 1., 1.])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "max_abs_cols = np.argmax(np.abs(v),axis = 0)\n",
    "signs = np.sign(v[max_abs_cols,[0,1,2,3]]) # 检索\n",
    "signs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "0f2994dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.36138659,  0.65658877, -0.58202985,  0.31548719],\n",
       "       [-0.08452251,  0.73016143,  0.59791083, -0.3197231 ],\n",
       "       [ 0.85667061, -0.17337266,  0.07623608, -0.47983899],\n",
       "       [ 0.3582892 , -0.07548102,  0.54583143,  0.75365743]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "aec51314",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.92461872, 0.05306648, 0.01710261, 0.00521218])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "w/w.sum() # 计算每个特征值的权重，百分比"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "00050a84",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.92461872, 0.97768521, 0.99478782, 1.        ])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(w/w.sum()).cumsum() # 累加和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "4b2dca0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False,  True,  True,  True])"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(w/w.sum()).cumsum() >= 0.95"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "bded6fd1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cond.argmax() # 当第一个为True时，索引就会返回~"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "227810d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([False, False,  True,  True])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "cond = (w/w.sum()).cumsum() >= 0.99 # 第一个为True的位置，刚好满足条件\n",
    "display(cond)\n",
    "index = cond.argmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "3be5d2fb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.92461872, 0.97768521, 0.99478782, 1.        ])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(w/w.sum()).cumsum()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "810cf8e9",
   "metadata": {},
   "source": [
    " ### SVD奇异值分解"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "16d876de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7, 0, 2],\n",
       "       [3, 4, 8],\n",
       "       [8, 5, 5],\n",
       "       [5, 1, 3],\n",
       "       [1, 7, 9]])"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A = np.random.randint(0,10,size = (5,3))\n",
    "A"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "76e3ffc0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-0.27486624, -0.59911305,  0.32168577],\n",
       "       [-0.49259234,  0.23437529,  0.5788527 ],\n",
       "       [-0.54635258, -0.3540899 , -0.67569993],\n",
       "       [-0.28188389, -0.31492276,  0.28503705],\n",
       "       [-0.55121836,  0.60131172, -0.15372476]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([18.51158186,  8.60190942,  2.30835253])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "array([[-0.5257951 , -0.47767634, -0.70382159],\n",
       "       [-0.84826361,  0.35588737,  0.39216455],\n",
       "       [-0.06315349, -0.80322444,  0.59231929]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "U,S,Vt = np.linalg.svd(A,full_matrices=False)\n",
    "display(U,S,Vt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0dda6469",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7.00000000e+00, 8.29820896e-16, 2.00000000e+00],\n",
       "       [3.00000000e+00, 4.00000000e+00, 8.00000000e+00],\n",
       "       [8.00000000e+00, 5.00000000e+00, 5.00000000e+00],\n",
       "       [5.00000000e+00, 1.00000000e+00, 3.00000000e+00],\n",
       "       [1.00000000e+00, 7.00000000e+00, 9.00000000e+00]])"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 奇异值分解，是约等于\n",
    "U.dot(np.diag(S)).dot(Vt)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "470379f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7, 0, 2],\n",
       "       [3, 4, 8],\n",
       "       [8, 5, 5],\n",
       "       [5, 1, 3],\n",
       "       [1, 7, 9]])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "A"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "66b08197",
   "metadata": {},
   "source": [
    "### SVD奇异值分解-PCA降维"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "5630f079",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786],\n",
       "       [-1.31993521],\n",
       "       [-1.40496732],\n",
       "       [-1.33510889],\n",
       "       [-1.32702321]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn import datasets\n",
    "from sklearn.decomposition import PCA\n",
    "X,y = datasets.load_iris(return_X_y=True)\n",
    "pca = PCA(n_components=0.90,whiten=True) # 筛选特征重要性99%特征\n",
    "X_pca = pca.fit_transform(X)\n",
    "display(X_pca[:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "ac134b27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786,  0.64836932, -0.09981716],\n",
       "       [-1.31993521, -0.35930856, -0.75257299],\n",
       "       [-1.40496732, -0.29424412,  0.0640073 ],\n",
       "       [-1.33510889, -0.64613986,  0.11284924],\n",
       "       [-1.32702321,  0.6633044 ,  0.32210314]])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n_components = 2\n",
    "# 1、去中心化\n",
    "B = X - X.mean(axis = 0)\n",
    "\n",
    "# 2、奇异值分解\n",
    "U,S,Vt = np.linalg.svd(B,full_matrices=False)\n",
    "\n",
    "# 3、符号翻转\n",
    "# 符号翻转，绝对值最大的，如果是负数，才翻转\n",
    "max_abs_cols = np.argmax(np.abs(U),axis = 0)\n",
    "signs = np.sign(U[max_abs_cols,[0,1,2,3]]) # 检索\n",
    "U *= signs # 根据条件进行翻转\n",
    "\n",
    "# 4、降维特征筛选\n",
    "# U = U[:,:n_components]\n",
    "cond = (S/S.sum()).cumsum() > 0.90\n",
    "index = cond.argmax()\n",
    "U = U[:,:index + 1]\n",
    "\n",
    "# 归一化\n",
    "U = (U - U.mean(axis = 0))/(U.std(axis = 0,ddof = 1))\n",
    "U[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "7ee013e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[-1.30533786],\n",
       "       [-1.31993521],\n",
       "       [-1.40496732],\n",
       "       [-1.33510889],\n",
       "       [-1.32702321]])"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X_pca[:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "189740e4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([25.09996044,  6.01314738,  3.41368064,  1.88452351])"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "S # 奇异值，如果根据比例进行筛选，那么得到结论和PCA，筛选的特征，就会不完全一样【接受】"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "cd3aee1c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[7, 0, 2],\n",
       "       [3, 4, 8],\n",
       "       [8, 5, 5],\n",
       "       [5, 1, 3],\n",
       "       [1, 7, 9]])"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "(5, 3)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(A, A.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "51bb4092",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "284.444px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
